<template>
        <div class>
          <el-card class="ep-card ep-search">
              <el-form :model="searchForm" label-width="80px">
                  <el-row :gutter="20">
                    <el-col :span="8">
                          <el-form-item label="项目编码" size="small"> 
                              <el-input v-model="searchForm.projCode"  placeholder="请输入项目编码"></el-input>
                          </el-form-item>
                      </el-col>
                      <el-col :span="8">
                          <el-form-item label="客户名称" size="small"> 
                              <el-input v-model="searchForm.projName"  placeholder="请输入客户名称"></el-input>
                          </el-form-item>
                      </el-col>
                      <el-col :span="8">
                          <el-form-item label="业务类型" prop='bizNature' >
                            <el-select v-model="searchForm.serviceType" placeholder="请选择" style="width: 100%;">
                              <el-option label="融资担保" value="1"></el-option>
                              <el-option label="非融资担保" value="2"></el-option>
                            </el-select>
                          </el-form-item>
                      </el-col>
                  </el-row>
                  <el-row>
                   <el-col :span="24" style="text-align:right ">
                      <el-button type="primary" size="small" icon="el-icon-search" @click="init">查询</el-button>
                    </el-col>
                  </el-row>
              </el-form>
          </el-card>
          <el-table :data="tableData" border style="width: 100%" size="mini">
            <el-table-column type="index" label="序号" align="center" width="50">
            </el-table-column>
            <el-table-column prop="projCode" label="项目编码" align="center" width="260">
            </el-table-column>
            <el-table-column prop="projName" label="客户名称" align="center" width="120">
            </el-table-column>
            <el-table-column prop="serviceType"  align="center" label="业务类型">
            </el-table-column>
            <el-table-column prop="guaterm" align="center" label="申请期限">
            </el-table-column>
            <el-table-column prop="curreny" align="center" label="申请金额(万元)">
            </el-table-column>
            <el-table-column prop="managera" align="center" label="项目经理A">
                <template slot-scope="scope">
                  <div v-for="item in users" :key="item.id">
                          <span v-show="item.id==scope.row.managera">
                              {{item.realName}}
                          </span>
                  </div>
              </template>
            </el-table-column>
            <el-table-column prop="managerb" align="center" label="项目经理B">
                <template slot-scope="scope">
                  <div v-for="item in users" :key="item.id">
                          <span v-show="item.id==scope.row.managerb">
                              {{item.realName}}
                          </span>
                  </div>
                </template>
            </el-table-column>
            <el-table-column prop="loanBank" align="center" label="申请贷款银行">
              <template slot-scope="scope">
                  <div v-for="item in bankList" :key="item.key">
                          <span v-show="item.key==scope.row.loanBank">
                              {{item.label}}
                          </span>
                  </div>
              </template>
            </el-table-column>
            <el-table-column
                        prop="handleTime"
                        align="center"
                        label="申请时间" type="date" :formatter="dateFormatter">
            </el-table-column>
            <el-table-column label="操作" align="center" width="100">
              <template slot-scope="scope">
                <el-button @click="handleClick(scope.row)" type="text" size="small">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-card style="text-align:right;">
            <el-pagination @size-change="sizeChange" @current-change="currentChange" :current-page="currentPage" :page-sizes="[ 10, 20,30, 40]" :page-size="pageSize" background layout="total, sizes, prev, pager, next" :total="total"></el-pagination>
          </el-card>
        </div>
      </template>
      
      <script>
export default {
  components: {},
  data() {
    return {
      total: 0,
      pageSize: 10,
      currentPage: 1,
      tableData: [],
      searchForm: {
        projCode:"",
        projName: "",
        serviceType:""
      },
      bankList:[
        {label:'农业银行',key:'1'},
        {label:'建设银行',key:'2'},
        {label:'工商银行',key:'3'}
      ],
      users:[]
    };
  },
  computed: {},
  mounted() {
    this.getusers();
    this.init();
    
  },
  methods: {
    getusers() {
      let params = {};
      this.$api
        .formPost(  "/api/auth/sysuser/doGetList", params)
        .then(res => {
          if (res.retHead.code == "0000000") {
            this.users = res.retBody.list;
          }
        });
    },
    dateFormatter(row) {
      return this.formatDate(row.createTime, "yyyy-MM-dd");
    },
    handleClick(row) {
      let params = {mid:row.id,
             workflowCode:"005"
      };
       this.$api.post(  "/wf/check",params).then(res => {
              if(res.status=='0'){
                this.delete(row);
              }else{
                 this.$confirm(res.message+",是否确定删除！", '提示', {
                      confirmButtonText: '确定',
                      cancelButtonText: '取消',
                      type: 'warning'
                  }).then(() => {
                     this.delete(row);
                  }).catch(() => {
                      this.$message({
                        type: 'info',
                        message: '已取消删除'
                      });          
                    });
              }
        });
      
    },
    sizeChange(n) {
      this.pageSize = n;
      this.init();
    },
    currentChange(n) {
      this.currentPage = n;
      this.init();
    },
    init() {
      let params = {
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        projCode:this.searchForm.projCode,
        projName: this.searchForm.projName,
        serviceType:this.searchForm.serviceType
      };
      this.$api
        .formPost(
            "/api/biz/project/doGetList",
          params
        )
        .then(res => {
          if (res.retHead.code === "0000000") {
            this.tableData = res.retBody.list;
            this.total = res.retBody.total;
          }
        });
    },
    delete(row){
          let params={
            id:row.id,
            serviceType:row.serviceType
          };
         this.$api.formPost(  "/api/biz/project/doRemove", params).then(res => {
            if (res.retHead.code === "0000000") {
               this.$message({
                      type: 'success',
                      message: '删除成功!'
                 });
               this.init();  
            }else{
              this.$message({
                      type: 'error',
                      message: "删除失败!"
                 });
            }
        });
    }
  },
  created() {}
};
</script>
      <style lang='scss' scoped>
</style>